#-*-coding:utf8;-*-

from ylTDX2 import * #from ylTDX import all def function
from  _utinity import *

"""
LC:=REF(CLOSE,1);
抄:SMA(MAX(CLOSE-LC,0),12,1)/SMA(ABS(CLOSE-LC),12,1)*100 LINETHICK2;
底:30 COLORRED LINETHICK3;
神:70 COLORGREEN LINETHICK3;
针:50  COLORYELLOW LINETHICK3;
"""
def cdsz(code,file_name=None): #file_name 是股票池，单股测试，不用此参数            
    df=get_data(code)
    OPEN=tdx(df["Open"].to_list()) #open 是file open
    HIGH=tdx(df["High"].to_list())
    LOW=tdx(df["Low"].to_list())
    CLOSE=tdx(df["Close"].to_list())
    VOL=tdx(df["Volume"].to_list())
    AMOUNT=tdx(df["Amount"].to_list())
    LC=REF(CLOSE,1)
    # v1=SMA(MAX(CLOSE-LC,0),12,1)  
    # v2=SMA(ABS(CLOSE-LC),12,1)
    # print(v1)
    # print(v2)
    抄=SMA(MAX(CLOSE-LC,0),12,1)/SMA(ABS(CLOSE-LC),12,1)*100
    if not 抄: #抄=[]
        print("error,data get fail")
    # print(抄)
    # 底=30
    # 神=70
    # 针=50
    if file_name is not None:
        output_File = open(file_name,'a+') 
        if len(抄)>0:
            output_File.write('{},{},{}\n'.format(str(code).zfill(6),str(round(抄[-1],2)),df['close'][-1]))
            output_File.flush()
        else:
            output_File.flush()
        return "%s complete"%str(code).zfill(6)

if __name__=='__main__':
    # ChaoDiShenZhen(600741)
    sort_stratedy(cdsz,ascending=True)